package com.itheima.jdk;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;

public class JDKPost {
    public static void main(String[] args)throws Exception {
        String u="http://www.itcast.cn";

        URL url = new URL(u);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        conn.setRequestMethod("POST");

        conn.setDoOutput(true);
        OutputStream outputStream = conn.getOutputStream();
        outputStream.write("username=liuqi&password=123".getBytes());

        InputStream inputStream = conn.getInputStream();

        int len;
        byte[] bytes = new byte[1024];
        while ((len=inputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }

        inputStream.close();
        outputStream.close();

    }
}
